﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace xKnight.WebCrawling.Core.HTTP
{
    public class RequestRedirectionResult
    {
        private List<HttpWebResponse> _responseSequence = new List<HttpWebResponse>();
        private List<Cookie> _cookies = new List<Cookie>();

        public int ResponseSequenceLength
        {
            get
            {
                return _responseSequence.Count;
            }
        }

        public HttpWebResponse this [int index]
        {
            get
            {
                return _responseSequence[index];
            }
        }

        public Cookie[] Cookies
        {
            get
            {
                return _cookies.ToArray();
            }
        }

        public HttpWebResponse LastResponse
        {
            get
            {
                if (_responseSequence.Count == 0)
                    return null;

                return _responseSequence[_responseSequence.Count - 1];
            }
        }

        public void AddResponse(HttpWebResponse httpWebResponse)
        {
            _responseSequence.Add(httpWebResponse);
        }

        public void AddCookies(Cookie[] cookies)
        {
            for(int i=0;i<cookies.Length;i++)
            {
                _cookies.Add(cookies[i]);
            }
        }
    }
}
